package com.gw.quotes.adapter;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gw.quotes.R;
import com.gw.quotes.entity.business.GetOrdersRecords.OrdersRecords;

public class Goods5Adapter extends BaseAdapter {

	private List<OrdersRecords> list;
	private Context context;
	private int resource;

	public Goods5Adapter(Context context, int layoutId, List<OrdersRecords> list) {
		this.context = context;
		this.resource = layoutId;
		this.list = list;
	}

	@Override
	public int getCount() {
		return this.list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		OrdersRecords ordersRecords = list.get(position);
		ViewHolder vh = null;
		if (convertView == null) {
			vh = new ViewHolder();
			convertView = LayoutInflater.from(this.context).inflate(
					this.resource, parent, false);
			vh.procurement_unit_tv = (TextView) convertView
					.findViewById(R.id.procurement_unit_tv);
			vh.closing_time_tv = (TextView) convertView
					.findViewById(R.id.closing_time_tv);
			vh.f5_tv_suppliername = (TextView) convertView
					.findViewById(R.id.f5_tv_suppliername);
			vh.f5_tv_qty = (TextView) convertView.findViewById(R.id.f5_tv_qty);
			vh.f5_tv_goodsprice = (TextView) convertView
					.findViewById(R.id.f5_tv_goodsprice);
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}

		vh.procurement_unit_tv.setText("采购单位："
				+ ordersRecords.getBuyerorgname());
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
				Locale.getDefault());// 设置日期格式
		vh.closing_time_tv.setText("成交时间:" + ordersRecords.getSuretime());
		vh.f5_tv_suppliername.setText(ordersRecords.getSuppliername());
		vh.f5_tv_qty.setText(ordersRecords.getQty() + "");
		vh.f5_tv_goodsprice.setText(String.format("￥%.2f", ordersRecords.getGoodsprice()));
		return convertView;
	}

	public class ViewHolder {
		TextView procurement_unit_tv;
		TextView closing_time_tv;
		TextView f5_tv_suppliername;
		TextView f5_tv_qty;
		TextView f5_tv_goodsprice;
	}
}
